package com.czxy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czxy.domain.City;
import com.czxy.domain.Classes;
import com.czxy.mapper.CityMapper;
import com.czxy.mapper.ClassesMapper;
import com.czxy.service.CityService;
import com.czxy.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CityServiceImpl extends ServiceImpl<CityMapper, City> implements CityService {

    @Autowired
    private CityMapper cityMapper;

    @Override
    public List<City> getAddress() {
        //1 查询一级分类，省
        List<City> provinceList = cityMapper.findByParentId("0");
        //2 遍历一级分类,查询二级分类  市（地级市）
        for (City pro:provinceList){
            List<City> cityList = cityMapper.findByParentId(pro.getId());
            pro.setChildren(cityList);

            //3 遍历二级分类，查询三级分类  区(县级市)
            for (City city:cityList){
                List<City> quList = cityMapper.findByParentId(city.getId());
                city.setChildren(quList);
            }
        }
        return provinceList;
    }

    @Override
    public List<City> findByParentId(String parentId) {
        return cityMapper.findByParentId(parentId);
    }
}
